package cn.z2huo.demo.multidatasource.mybatis.dao;

import cn.z2huo.demo.example.user.UserDOExample;
import cn.z2huo.demo.mapper.user.UserMapper;
import cn.z2huo.demo.model.dataobject.user.UserDO;
import jakarta.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *
 * @author z2huo
 */
@Repository
public class UserDAO {

    @Autowired
    private UserMapper userMapper;

    @Nullable
    public UserDO getUserByUserCode(String userCode) {
        if (StringUtils.isBlank(userCode)) {
            return null;
        }

        UserDOExample userDOExample = new UserDOExample();
        UserDOExample.Criteria criteria = userDOExample.createCriteria();
        criteria.andUserCodeEqualTo(userCode);
        List<UserDO> userDOS = userMapper.selectByExample(userDOExample);
        return userDOS.getFirst();
    }

}
